package Chapter2.Comparing.c3;

public class Practice2 {
    public static void main(String[] args) {
       /* String s = "abcdefg";
        String s2 = s.substring(2,6);
        StringBuffer sb = new StringBuffer(s2);

        StringBuffer sb2 = sb.reverse();

       String s3 = sb2.insert(0,"ab").append("g").toString();
        System.out.println("s3:"+s3);
        */
       //先定义一个字符串
       String s = "abcdefg";
       //String s2 = s.substring(2,6);
       //将字符串转化成字符数组
       char[] chs = s.toCharArray();
        System.out.println(chs);
       //写一个功能
       char[] chs2 =  getArray(chs);
        //System.out.println(chs2);

        String sb = new StringBuffer(String.valueOf(chs2)).toString();

        System.out.println(sb);

    }

    public static char[] getArray(char[] chs){
        for(int i = 0 ; i < 4; i++){
            for (int x = 2;x < chs.length-2;x++) {
                if (chs[x] < chs[x + 1]) {
                    char temp = chs[x];
                    chs[x] = chs[x + 1];
                    chs[x + 1] = temp;
                }
            }
        }

        return chs;
    }

    /*public static void main(String[] args) {
        String str2 = "abcdefg";
        String str3 = reverse(str2,2,5);
        System.out.println(str3);
    }

    public static String reverse(String s, int start, int end) {
        String s1 = s.substring(0, start);
        for (int i = end; i >=start; i--) {
            char c = s.charAt(i);
            s1 = s1 + c;
        }
        s1 = s1 + s.substring(end+1);
        return s1;
    }*/
}
